{% extends "admin/master.volt" %}
{% block content %}
    <header class="bar bar-nav">
        <h1 class='title'>管理员登录</h1>
    </header>
    <div class="content">
        <div class="list-block">
            <ul>
                <!-- Text inputs -->
                <li>
                    <div class="item-content">
                        <div class="item-media"><i class="icon icon-form-name"></i></div>
                        <div class="item-inner">
                            <div class="item-title label">用户名</div>
                            <div class="item-input">
                                <input type="text" placeholder="用户名" id="username">
                            </div>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="item-content">
                        <div class="item-media"><i class="icon icon-form-email"></i></div>
                        <div class="item-inner">
                            <div class="item-title label">密码</div>
                            <div class="item-input">
                                <input type="password" placeholder="密码" id="password">
                            </div>
                        </div>
                    </div>
                </li>
            </ul>
        </div>
        <div class="content-block">
            <a onclick="sub(this)" data-url="{{ url('/admin/login/login') }}" data-target="{{ url('admin/index') }}"
               class="button button-big button-fill button-success">登录</a>
        </div>
    </div>
{% endblock %}
{% block js %}
    <script>
        function sub(e) {
            var username = $("#username").val();
            var password = $("#password").val();
            var json = {
                "username": username,
                "password": password
            };
            var url = $(e).attr('data-url');
            var target = $(e).attr('data-target');
            $.post(url, json, function (jsonData) {
                if (jsonData.status == 1) {
                    location = target;
                } else {
                    $.toast(jsonData.message);
                }
            }, "json");
        }
    </script>
{% endblock %}